package com.muki.succ.web.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.muki.spider.SpiderManager;
import com.muki.succ.core.Manager;
import com.muki.succ.registery.SpiderManagerHall;
import com.muki.succ.web.service.ManagerService;

@Service
public class ManagerServiceImpl implements ManagerService {

	private SpiderManagerHall hall = SpiderManagerHall.newInstance();
	
	@Override
	public List<Manager> getManagerNames() {
		List<Manager> managers = hall.getAllManager();
		for(Manager manager:managers) {
			SpiderManager spider = hall.findByName(manager.getTopic());
			if(spider!=null) {
				manager.setCount(spider.getNum(manager.getTopic()));
			}
		}
		return managers;
	}

	@Override
	public Manager findByName(String topic) {
		List<Manager> managers = hall.getAllManager();
		for(Manager m:managers) {
			if(m.getTopic().equals(topic))
				return m;
		}
		return null;
	}

}
